// import React from "react";
import React from "./react";

function Child (props,ref){
  const inputRef = React.useRef()
  React.useImperativeHandle(ref,()=>{ // 自定义ref.current
    return {
      focus(){
        inputRef.current.focus()
      }
    }
  })
  return (<input type={'text' } ref={inputRef} />)
}

const ForwardChild = React.forwardRef(Child)
function App (){
  const ref = React.useRef()
  const getFocus = ()=>{
    ref.current.focus()
  }
  return <div>
      <ForwardChild  ref={ref}/>
      <button onClick={getFocus}>获取焦点</button>
    </div>
}
export default App